﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ProgrammingIsMyPassion.Coding.Test
{
    [TestClass]
    public class ReArrangeArrayProblemTest
    {
        private bool IsCorrectSolution(int[] expected)
        {
            var A = expected;
            for (int i = 1; i < A.Length - 1; i++)
            {
                if (i % 2 == 0)
                {
                    if (A[i] <= A[i - 1] && A[i] <= A[i + 1])
                        continue;
                    else return false;
                }
                if (i % 2 != 0)
                {
                    if (A[i] >= A[i - 1] && A[i] >= A[i + 1])
                        continue;
                    else return false;
                }

            }
            return true;
        }

        [TestMethod]
        public void Solution1Test()
        {
            //arrange
            ReArrangeArrayProblem solution1 = new ReArrangeArrayProblem();
            int[] A = new int[] { 3, 4, 2, 7, 1, 9, 6 };
            //act
            var expected  = solution1.Solution1(A);

            //asssert
           Assert.IsTrue(IsCorrectSolution(expected));
        }

        [TestMethod]
        public void Solution2Test()
        {
            //arrange
            ReArrangeArrayProblem solution1 = new ReArrangeArrayProblem();
            int[] A = new int[] { 3, 4, 2, 7, 1, 9, 6 };
            //act
            var expected = solution1.Solution2(A);

            //asssert
            Assert.IsTrue(IsCorrectSolution(expected));
        }
        
    }
}
